--[[
local skilltreedef = require("prefabs/skilltree_defs")
local skilltreedata = require("prefabs/skilltree_kkd")(skilltreedef.FN)
skilltreedef.CreateSkillTreeFor("kukude", skilltreedata.SKILLS)
skilltreedef.SKILLTREE_ORDERS["kukude"] = skilltreedata.ORDERS


local OldGetSkilltreeBG = GLOBAL.GetSkilltreeBG
GLOBAL.GetSkilltreeBG = function(imagename,...)
	if imagename == "kukude_background.tex" then
		return "images/kukude_background.xml"       --重定位到自己的技能背景上，需要去xml里把资源名改成“esctemplate_background”
    end
	return OldGetSkilltreeBG(imagename, ...)
end]]

--[[AddClassPostConstruct("skilltreedata", function(self)
    self = require("core_kukude/data/skilltreedata")()
end)


AddPrefabPostInit("kukude", function(inst)
    local LoadComponent
    local i = 1
    while true do
        local name, fn = debug.getupvalue(inst.AddComponent, i)
        if name == nil then break end
        if name == "LoadComponent" then
            LoadComponent = fn
            break
        end
        i = i + 1
    end
    local function AddComponentAs(self, name, name2)
        name2 = name2 or name
        local lower_name = string.lower(name2)
        if self.lower_components_shadow[lower_name] ~= nil then
            print("component "..name.." already exists on entity "..tostring(self).."!"..debugstack_oneline(3))
            local existingcmp = self.components[lower_name]
            if existingcmp == nil then
                for k, v in pairs(self.components) do
                    if string.lower(k) == lower_name2 then
                        existingcmp = v
                        break
                    end
                end
            end
            return existingcmp
        end
    
        local cmp = LoadComponent(name)
        if not cmp then
            error("component ".. name .. " does not exist!")
        end
    
        self:ReplicateComponent(name)
    
        local loadedcmp = cmp(self)
        self.components[name2] = loadedcmp
        self.lower_components_shadow[lower_name] = true
    
        local postinitfns = ModManager:GetPostInitFns("ComponentPostInit", name2)
    
        for _, fn in ipairs(postinitfns) do
            fn(loadedcmp, self)
        end
    
        self:RegisterComponentActions(name)
    
        return loadedcmp
    end
    inst:RemoveComponent("skilltreeupdater")
    AddComponentAs(inst, "kukude_skilltreeupdater", "skilltreeupdater")
end)
local skilltreebuilder = require("widgets/kkd/redux/skilltreebuilder") 

AddClassPostConstruct("widgets/redux/skilltreewidget", function(self)
    if self.target == "kukude" then
        self.root.tree:Kill()
        self.root.tree = self.root:AddChild(skilltreebuilder(self.root.infopanel, self.fromfrontend, self))
        self.root.tree:SetPosition(0,-50)
        print("skilltreebuilder success")
        self.root.tree:CreateTree(self.target, self.targetdata, self.readonly)
        if self.root.tree then
            self.root.tree:SetFocusChangeDirs()
            self.default_focus = self.root.tree:GetDefaultFocus()
        end
    end
end)
]]

if MSGA_UTIL then
    MSGA_UTIL.MakeSkillTree("kukude", "core_kukude/callers/skilltree_lan") --, {"images/kukude_background.xml", "kukude_background.tex"})
end